package com.yanqu.road.dao.impl.activity.peakstronghold;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorConfig;
import com.yanqu.road.entity.activity.peakstronghold.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class PeakStrongholdActivityDaoImpl extends TempDao {


    public static String getPeakStrongholdDesertConfigSql = "select * from t_s_activity_desert_floor where activityId = ?";

    public Map<Integer, HuaShiGangFloorConfig> getPeakStrongholdDesertConfig(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, HuaShiGangFloorConfig> configMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakStrongholdDesertConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HuaShiGangFloorConfig strongholdDesertConfig = new HuaShiGangFloorConfig();
                strongholdDesertConfig.setActivityId(rs.getInt("activityId"));
                strongholdDesertConfig.setFloor(rs.getInt("floor"));
                strongholdDesertConfig.setSpecialReward(rs.getString("specialReward"));
                strongholdDesertConfig.setRewards(rs.getString("rewards"));
                strongholdDesertConfig.setConsume(rs.getString("consume"));
                configMap.put(strongholdDesertConfig.getFloor(), strongholdDesertConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return configMap;
    }

    public static String getPeakStrongholdDonateConfigSql = "select * from t_s_activity_peak_hold_base where activityId = ?";

    public Map<Integer, PeakStrongholdBaseConfig> getPeakStrongholdBaseConfig(int activityId){
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, PeakStrongholdBaseConfig> configMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakStrongholdDonateConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakStrongholdBaseConfig strongholdDonateConfig = new PeakStrongholdBaseConfig();
                strongholdDonateConfig.setActivityId(rs.getInt("activityId"));
                strongholdDonateConfig.setId(rs.getInt("id"));
                strongholdDonateConfig.setIcon(rs.getString("icon"));
                strongholdDonateConfig.setLevel(rs.getInt("level"));
                strongholdDonateConfig.setHpAdd(rs.getInt("hpAdd"));
                strongholdDonateConfig.setNeedProcess(rs.getString("needProcess"));
                configMap.put(strongholdDonateConfig.getLevel(), strongholdDonateConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return configMap;
    }

    public static String getPeakStrongholdTimeConfigSql = "select * from t_s_activity_peak_hold_time where activityId = ?";

    public Map<Integer, PeakStrongholdTimeConfig> getPeakStrongholdTimeConfig(int activityId)  {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, PeakStrongholdTimeConfig> configMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakStrongholdTimeConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakStrongholdTimeConfig strongholdTimeConfig = new PeakStrongholdTimeConfig();
                strongholdTimeConfig.setActivityId(rs.getInt("activityId"));
                strongholdTimeConfig.setTimeId(rs.getInt("timeId"));
                strongholdTimeConfig.setType(rs.getInt("type"));
                strongholdTimeConfig.setBeginTime(rs.getInt("beginTime"));
                strongholdTimeConfig.setDurationTime(rs.getInt("durationTime"));
                strongholdTimeConfig.setParam(rs.getString("param"));
                strongholdTimeConfig.setScore(rs.getString("score"));
                configMap.put(strongholdTimeConfig.getTimeId(), strongholdTimeConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return configMap;
    }

    public Map<Integer, PeakStrongholdDonateConfig> getPeakStrongholdDonateConfig(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, PeakStrongholdDonateConfig> configMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            String sql = "select * from t_s_activity_peak_hold_donate where activityId = ?";
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakStrongholdDonateConfig strongholdTimeConfig = new PeakStrongholdDonateConfig();
                strongholdTimeConfig.setActivityId(rs.getInt("activityId"));
                strongholdTimeConfig.setId(rs.getInt("id"));
                strongholdTimeConfig.setConsume(rs.getString("consume"));
                strongholdTimeConfig.setExp(rs.getInt("exp"));
                strongholdTimeConfig.setMaxNum(rs.getInt("maxNum"));
                strongholdTimeConfig.setRewards(rs.getString("rewards"));
                configMap.put(strongholdTimeConfig.getId(), strongholdTimeConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return configMap;
    }
}
